﻿Public Class UniDetails
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
    End Sub


    Protected Sub btn_comment_submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_comment_submit.Click
        Dim uniID As Integer = Request.QueryString("ID")
        If txtB_comments.Text = "" And rbl_comment_rating.SelectedValue = False Then
            lbl_validate_comments.Text = "* Please enter All fields"
        Else
            Dim Uid As Integer
            Dim Uname As String = Page.User.Identity.Name
            Uid = CInt(userID(Uname))
            Dim sql As String = " INSERT INTO comments (UserID, UniversityID, Comments, CommentDate ) VALUES (@v1, @v2, @v3, v4)"
            Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("UniConnectionString").ConnectionString)
            Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, conn)
            cmd.Parameters.AddWithValue("@v1", Uid)
            cmd.Parameters.AddWithValue("@v2", uniID)
            cmd.Parameters.AddWithValue("@v3", txtB_comments.Text)
            cmd.Parameters.AddWithValue("@v4", Date.Today)
            rating()
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
            cmd.Dispose()
            conn.Dispose()
            txtB_comments.Text = String.Empty
        End If
        Response.Redirect("Details.aspx?ID=" & uniID)
    End Sub
    Protected Function userID(ByVal uname As String) As Integer
        Dim uID As Integer
        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("UniConnectionString").ConnectionString)
        conn.Open()
        Dim IDsql As String = " select aspnet_Users.UserId from aspnet_Users Where aspnet_Users.UserName = '" & uname & "'"
        Dim IDcmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(IDsql, conn)
        Dim Dreader As OleDb.OleDbDataReader
        Try
            Dreader = IDcmd.ExecuteReader()
            Dreader.Read()
            uID = Dreader("UserId")
        Catch
        End Try
        Return uID
        conn.Close()
        IDcmd.Dispose()
        conn.Dispose()
    End Function

    Protected Sub rating()
        Dim Uid As Integer
        Dim Uname As String = Page.User.Identity.Name
        Uid = CInt(userID(Uname))
        Dim uniID As Integer = Request.QueryString("ID")
        Dim sql As String = " INSERT INTO Rating (UniversityID, rating, userID) VALUES (@v1,@v2,@v3)"
        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("UniConnectionString").ConnectionString)
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@v1", uniID)
        cmd.Parameters.AddWithValue("@v2", rbl_comment_rating.SelectedValue)
        cmd.Parameters.AddWithValue("@v2", Uid)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
    End Sub

    Protected Sub btn_GoGallery_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_GoGallery.Click
        Dim uniID As Integer = Request.QueryString("ID")
        Response.Redirect("Gallery.aspx?UID=" & uniID & "")
    End Sub
End Class